package mrusanov.ui.stats

import javax.swing.JPanel
import mrusanov.util.swing.{ Event, EventConsumer, HolderPanel }
import mrusanov.nation.World
import net.miginfocom.swing.MigLayout
import mrusanov.ui.CentralPanel
import mrusanov.ui.PanelBuilder

class ResultsPanel(world: World, defaultSelection: Vector[Int] = Vector(0)) extends CentralPanel with EventConsumer[JPanel] {
	private val selectedRoundResults = new HolderPanel[JPanel]
	private val tree = new TreeBuilder(world).buildTree
	private val comboBoxesTree = new ComboBoxTreeHandlerPanel(tree)

	comboBoxesTree.addEventConsumer(this)
	comboBoxesTree.selection = defaultSelection
	setLayout(new MigLayout("fill"))
	add(comboBoxesTree, "wrap")
	add(selectedRoundResults, "grow,push")

	override def consumeEvent(event: Event[JPanel]) {
		selectedRoundResults.child = event.obj
	}

	override def buildItself(panelBuilder: PanelBuilder) = panelBuilder.results

}
